package com.orange.base.component.biztool.simulateddata.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.orange.base.component.biztool.simulateddata.service.SimulatedDataParam;

public abstract class AbstractWord extends AbstractJson {

    public static final Map<String, Object> CACHE = new HashMap<String, Object>();

    public abstract String getFileName();

    @SuppressWarnings("unchecked")
    public Map<String, Object> getData() {
        List<Map<String, Object>> datas = (List<Map<String, Object>>) super.getData(null, "list");
        int index = getRandomNumber(0, datas.size() - 1);
        return datas.get(index);
    }

    public String generate(SimulatedDataParam param) {
        StringBuilder sb = new StringBuilder("");
        int max = toInt(param.getMax(), 0);
        if (max == 0) {
            return getWord();
        }
        for (int i = 0; i < max; i++) {
            sb.append(getWord());
        }
        return sb.toString();
    }

    public abstract String getWord();

}
